package com.hzit.controller;

import com.hzit.entity.PageResult;
import com.hzit.entity.R;
import com.hzit.service.IStudentService;
import com.hzit.dto.StudentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private IStudentService studentService;

	//1. 查询所有学生
	@GetMapping("/list")
	public R list(){
		List<StudentDTO> students = studentService.findAll();
		return R.ok(students);
	}

	//2. 分页查询
	@GetMapping("/findPage")
	//前端传入两个参数page,pageSize,原因是最终执行sql语句：
	// select * from student limit (page-1)*pageSize,pageSize;
	public R findPage(int page,int pageSize){
		PageResult<StudentDTO> ps = studentService.findPage(page,pageSize);
		return R.ok(ps);
	}
}
